package com.lagou.order;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


/**
 * 封装Bean对象，用来保存id和数据
 */
public class OrderBean implements WritableComparable<OrderBean> {
    private Integer id;
    private Integer number;

    public OrderBean() {
    }

    public OrderBean(Integer id, Integer number) {
        this.id = id;
        this.number = number;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    //   指定从小到大排序
    public int compareTo(OrderBean o) {
        if (this.number > o.number){
            return 1;
        }else {
            return -1;
        }
    }

    public void write(DataOutput out) throws IOException {
        out.writeInt(id);
        out.writeInt(number);
    }

    public void readFields(DataInput in) throws IOException {
        this.id = in.readInt();
        this.number = in.readInt();
    }


    //    指定输出格式为id number
    @Override
    public String toString() {
        return id + "\t" + number;
    }


}

